//
//  HBMembershipFooterView.m
//  HeartBeat
//
//  Created by karong on 2023/9/11.
//

#import "HBMembershipFooterView.h"

@interface HBMembershipFooterView ()

@property (weak, nonatomic) IBOutlet YYLabel *label;

@end


@implementation HBMembershipFooterView

- (void)awakeFromNib {
    [super awakeFromNib];
    self.label.attributedText = [HBMembershipFooterView vipTextWithTapAction:^(NSString *string1, NSString *string2) {
        if ([self.delegate respondsToSelector:@selector(vipFooterViewWebAction:title:)]) {
            [self.delegate vipFooterViewWebAction:string1 title:string2];
        }
    }];
}

+ (NSMutableAttributedString *)vipTextWithTapAction:(回调两个字符串)tapAction {
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    style.alignment = NSTextAlignmentLeft;
    style.lineBreakMode = NSLineBreakByWordWrapping;
    NSString *text = WSLocalized(@"開通說明：\n\n1.開通前請先閱讀《會員服務協議》\n2.開通會員後請耐心等待，若VIP圖標未亮起，請嘗試重新登錄或提交意見反饋等待系統處理；\n3. 充值不支持退款；\n4. 充值的VIP僅適用本平台；\n5. 會員已閱讀的VIP章節不會永久解鎖，需要在有會員身份時才可以閱讀；");
    NSMutableAttributedString *attrText = [[NSMutableAttributedString alloc] initWithString:text
                                                                                 attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12], NSParagraphStyleAttributeName: style, NSForegroundColorAttributeName: UIColor.font_gray_999999}];
    NSString *string5 = SF(@"《%@》", WSLocalized(@"會員服務協議"));
    NSRange range5 = [text rangeOfString:string5];
    [attrText addAttributes:@{NSUnderlineStyleAttributeName: @(1)} range:range5];
    [attrText setTextHighlightRange:range5 color:UIColor.font_yellow_FFCC00 backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        tapAction?tapAction(API_HEARTBEAT_AGREEMENT_VIP, WSLocalized(@"會員服務協議")):nil;

    }];
    return attrText;
}

+ (CGFloat)cellHeight {
    CGFloat height = [[self vipTextWithTapAction:nil] boundingRectWithSize:CGSizeMake(HBScreenWidth - 31, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size.height;
    return  height;
}
@end
